Uec3.receivableIndexWindow = Ext.extend(Ext.app.Module, {
    id: 'receivable_index',
    objsCollection:new Ext.util.MixedCollection(true),
    getObjByKey:function(key){
		return this.objsCollection.get(key);
	},

    getPanel:function(params) {
   	var module=this;
   	var receivableArray=new Ext.util.MixedCollection(false);
	var record=Ext.data.Record.create( [ 
		{
			name : 'id',
			type : 'int',
			mapping : 'id'
		}, {
			name : 'companyId',
			type : 'int',
			mapping : 'companyId'
		}, {
			name : 'customerId',
			type : 'int' ,
			mapping : 'customerId'
		}, {
			name : 'customerName',
			type : 'string',
			mapping : 'customerName'
		}, {
			name : 'code',
			type : 'string',
			mapping : 'code'
		}, {
			name : 'documentType',
			type : 'int',
			mapping : 'documentType'
		}, {
			name : 'documentId',
			type : 'int',
			mapping : 'documentId'
		} , {
			name : 'documentCode',
			type : 'string',
			mapping : 'documentCode'
		},{
			name : 'documentTypeName',
			type : 'string',
			mapping : 'documentTypeName'
		},  {
			name : 'receivable',
			type : 'double',
			mapping : 'receivable'
		},  {
			name : 'received',
			type : 'double',
			mapping : 'received'
		}, {
			name : 'status',
			type : 'int',
			mapping : 'status'
		}, {
			name : 'statusName',
			type : 'string',
			mapping : 'statusName'
		},{
			name : 'gmtCreate',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtCreate'
		},{
			name : 'gmtModify',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtModify'
		},{
			name : 'gmtPaid',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtPaid'
		},{
			name : 'workFlowId',
			type : 'int',
			mapping : 'workFlowId'
		}, {
			name : 'currentorId',
			type : 'int',
			mapping : 'currentorId'
		}]);
		var store=new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy( {
				url : Uec3.App.Constants.homeUrl+'/receivable/base!extList.do'
			}),
			pruneModifiedRecords : true,
			paramNames : {
				start : "start",
				limit : "limit",
				sort : "sort",
				dir : "dir"
			},
			remoteSort:true,
			reader : new Ext.data.JsonReader( {
				totalProperty : 'totalProperty',
				root : 'root'
			}, record),
			listeners:{
			
			}
		});
		module.objsCollection.add("store",store);
	var selectM=new Ext.grid.CheckboxSelectionModel({
				listeners:{
					'beforerowselect':function(obj,rowIndex,keepExisting,record){
						if(receivableArray.length>0){
							if(receivableArray.itemAt(0).data.customerId!=record.data.customerId){
								Ext.Msg.alert("警告","请选中相同客户");
									return false;
							}
						}
					},
					'rowselect':function (obj,rowIndex,record) {
						receivableArray.add(record);
					},
					'rowdeselect':function (obj,rowIndex,record) {
						receivableArray.remove(record);
					}
					
				}
		})
	var columnModel = new Ext.grid.ColumnModel( [ 
		new Ext.grid.RowNumberer(), 
		selectM,
		{
		header : '应收款凭证号',
		width : 90,
		sortable : true,
		align:"right",
		dataIndex : 'code'
		},
		{
		header : '客户公司名称',
		width : 150,
		sortable : true,
		dataIndex : 'customerName'
		},
		{
		header : '状态',
		width : 75,
		sortable : true,
		dataIndex : 'statusName'
		},
		{
		header : '单据号',
		width : 75,
		sortable : true,
		dataIndex : 'documentCode'
		},
		{
		header : '单据类型',
		width : 75,
		sortable : true,
		dataIndex : 'documentTypeName'
		},
		{
		header : '应收总金额',
		width : 75,
		sortable : true,
		align:"right",
		dataIndex : 'receivable'
		},
		{
		header : '已收金额',
		width : 75,
		sortable : true,
		align:"right",
		dataIndex : 'received'
		},
		{
		header : '创建日期',
		width : 75,
		sortable : true,
		align:"right",
		renderer:Ext.util.Format.dateRenderer("Y-m-d"),
		dataIndex : 'gmtCreate'
		},
		{
		header : '修改日期',
		width : 130,
		sortable : true,
		align:"right",
		renderer:Ext.util.Format.dateRenderer("Y-m-d"),
		dataIndex : 'gmtModify'
		},
		{
		header : '支付结束日期',
		width : 130,
		sortable : true,
		align:"right",
		renderer:Ext.util.Format.dateRenderer("Y-m-d"),
		dataIndex : 'gmtPaid'
		}]);
				
	var grid=new Ext.grid.GridPanel({
	    cm:columnModel,
	    sm:selectM,
		store : store,
		iconCls : 'icon-grid',
		loadMask : {
			msg : '数据加载中...'
		},
		stripeRows : true,
		autoScroll : true,
		//autoload : true,
		height : 300,
		width : '100%',
		bbar : new Ext.PagingToolbar({
			pageSize : 10,
			store : store,
			displayInfo : true,
			style : 'align:center',
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录",
			listeners:{
					//翻页前
					'beforechange':function(){
						//payOperation();
					},
					'change':function(){
						var rowIdArray=[];
						Ext.each(store.getRange(),function(spayable){
							Ext.each(receivableArray.getRange(),function(payable){
								var rowId=store.indexOfId(spayable.id);
								if(rowId!=-1&&spayable.id==payable.id){
									rowIdArray.push(rowId);
								}
							});
						});
						grid.getSelectionModel().selectRows(rowIdArray);
					}
			}
		}),
		tbar:new Ext.Toolbar([
			'-',
			{
			text:'收款',
			iconCls : 'icon-payable',
			handler:function(){
				var isError=false;
				if(receivableArray.length==0){
					Ext.Msg.alert("信息","请选记录");
					return;
				}
				var receivableIds="";
				receivableArray.each(function(payable){
					receivableIds+=payable.id+",";
				});
				receivableIds=Ext.util.Format.substr(receivableIds,0,receivableIds.length-1);
				OpenOtherWindow({receivableIds:receivableIds,customerId:receivableArray.first().data.customerId,winId:"auto_"+receivableIds});
			
			}
			},
			'-',{
			text:'清空选择',
			iconCls : 'icon-clear',
			handler:function(){
				receivableArray.clear();
				payable_grid.getSelectionModel().clearSelections();
			}
			},'-']
		)
	});	
	module.objsCollection.add("grid",grid);
	
	var formPanel = new Ext.FormPanel({
		labelAlign : 'right',
		frame : true,
		items : [{
				  height:60,
		          layout:'hbox',
		          border:false,
		          layoutConfig: 
		             {     
		               padding:'5',
					   align:'middle' 
                  },            
		          items:[			             
		             {
		               xtype:'label',
		               text:'浏览应收款单',
		               style: {font:'bold 30px arial,serif'}
		             },{
		                xtype:'spacer',
                        flex:1
		             },{
                        xtype:'textfield',
                        name:'code'
                     },{
                        xtype:'button',
                        text:'查找单据号',                   
                        margins:'0 10',
                        handler:function(){
                        	
                        }
                     },{
                        xtype:'spacer',
                        flex:1
                     }]
			
		},grid]
	});
	
	function OpenOtherWindow(obj){
		var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam("saleInvoice_operation",obj); 
	}
	return formPanel;
	},
	initEvent:function(){
		var module=this;
		var win=module.getObjByKey("win");
		win.on('show',function(){
			this.getObjByKey("store").load();
		},module,{single:true});
	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();   
      var win = desktop.getWindowByUecId(windowId);
      if(!win){ 
      	var module=this;
         win = desktop.createWindow({
            uecId: windowId,
            width: 800,
            height: 500,
            title:'应收款列表',
            iconCls: 'acc-icon',
            shim: false,
            moduleObj:module,
            //animCollapse: true,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[params=='undefined'?this.getPanel():this.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.last();
            		var winMinWidth=900;
            		var winMinHeight=440;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-110);
            		}else{
            			grid.setHeight(height-110);
            		}
            	}
            }
         });
         module.objsCollection.add("win",win);
         module.initEvent();
      } 
      win.show();
   }
	});
